package com.labtalk.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.labtalk.admin.pojo.common.ResponseVo;
import com.labtalk.admin.pojo.entity.BarcodeEntity;
import com.labtalk.admin.pojo.model.BarcodeModel;
import com.labtalk.admin.service.BarcodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/api")
public class BarcodeController {

    @Autowired
    BarcodeService barcodeService;

    @GetMapping("/barcode")
    public ResponseVo getList(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                              @RequestParam(value = "pageSize", defaultValue = "2") Integer pageSize) {
        return barcodeService.getList(new Page<BarcodeEntity>(pageNo, pageSize));
    }

    @PostMapping("/barcode")
    public ResponseVo create(@RequestBody BarcodeModel model) {
        return barcodeService.create(model);
    }

    @PutMapping("/barcode")
    public ResponseVo update(@RequestBody BarcodeModel model) {
        return barcodeService.update(model);
    }

    @DeleteMapping("/barcode/{id}")
    public ResponseVo update(@PathVariable String id) {
        return barcodeService.delete(id);
    }

    @PostMapping("/barcode/upload")
        public ResponseVo upload(@RequestParam(value = "file") MultipartFile file) throws IOException {
        return barcodeService.upload(file);
    }
}
